export default {
	data() {
		return {
			searchForm: {}, // 查询时更新表单数据
			tableData: [], // table数据
			page: {
				total: 0, // 总页数
				currentPage: 1, // 当前页数
				pageSize: 20, // 每页显示多少条
			},
			tableLoading: false,
		};
	},
	methods: {
		//获取列表
		getList(val) {
			this.tableData = [];
			let page = val ? val : this.page;
			this.tableLoading = true;
			this.fetchList(
				Object.assign(
					{
						current: page.currentPage,
						size: page.pageSize,
					},
					//自定义搜索内容方法
					this.searchFormFormatter ? this.searchFormFormatter(this.searchForm) : this.searchForm
				)
			)
				.then((response) => {
					//自定义返回数据方法
					if (this.dataLoadOverBack) {
						this.dataLoadOverBack(response);
					} else {
						this.tableData = response.data.records || [];
						this.page.total = response.data.total || 0;
					}

					this.tableLoading = false;
				})
				.catch(() => {
					this.tableLoading = false;
				});
		},
		// 每页数量变更
		sizeChange(pageSize) {
			this.page.pageSize = pageSize;
			this.getList();
		},
		// 页数变更
		currentChange(current) {
			this.page.currentPage = current;
			this.getList();
		},
		// 点击搜索执行
		searchChange(form, done) {
			this.searchForm = form;
			this.page.currentPage = 1;
			this.getList(this.page);
			done();
		},
		// 点击刷新按钮触发
		refreshChange() {
			this.getList(this.page);
		},
	},
};
